<template>
  <div>
    <a-modal @ok="submit" centered v-model:open="visible" title="更新基站">
      <a-form ref="formRef" :model="form" layout="vertical" @submit="submit">
        <a-form-item label="基站ID">
          <a-input v-model:value="form.id" disabled />
        </a-form-item>
        <a-form-item label="选择类型" name="type" required>
          <a-radio-group :options="updateOptions" v-model:value="form.type"></a-radio-group>
        </a-form-item>
        <a-form-item label="上传文件" name="uri">
          <Uploader v-model:uri="form.uri" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
import { upgradeStation } from '@/api/modules/esl/station';
import { notify } from '@/utils/common/common';

const visible = defineModel<boolean>('visible');

const formRef = ref();
const props = defineProps<{
  id: string;
}>();
const form = ref({
  type: 0,
  uri: '',
  id: '',
});

const updateOptions = [
  {
    label: '网关应用',
    value: 0,
  },
  {
    label: '基站射频',
    value: 1,
  },
  {
    label: 'webSocket',
    value: 2,
  },
];
const submit = async () => {
  const hasPassed = await formRef.value?.validate();

  if (hasPassed) {
    const { data } = await upgradeStation(form.value);
    notify(data);
    visible.value = false;
  }
};
watch(
  props,
  () => {
    form.value.id = props.id;
  },
  {
    deep: true,
    immediate: true,
  },
);
</script>

<style lang="scss" scoped></style>
